home *** CD-ROM | disk | FTP | other *** search
/ Amiga Tools 4 / Amiga Tools 4.iso / tools / netzwerk / tcp-ip / ipdial_v1.9 / setvar.c < prev    next >
C/C++ Source or Header  |  1996-02-26  |  2KB  |  92 lines

  1. /**
  2. ***  IPDial     Script program for initializing a SLIP connection
  3. ***  Copyright  (C)   1994    Jochen Wiedmann
  4. ***
  5. ***  This program is free software; you can redistribute it and/or modify
  6. ***  it under the terms of the GNU General Public License as published by
  7. ***  the Free Software Foundation; either version 2 of the License, or
  8. ***  (at your option) any later version.
  9. ***
  10. ***  This program is distributed in the hope that it will be useful,
  11. ***  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ***  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ***  GNU General Public License for more details.
  14. ***
  15. ***  You should have received a copy of the GNU General Public License
  16. ***  along with this program; if not, write to the Free Software
  17. ***  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. ***
  19. ***
  20. ***
  21. ***  This file contains a function to set an environment variable.
  22. ***
  23. ***
  24. ***  Computer: Amiga 1200                       Compiler: Dice 3.01
  25. ***
  26. ***  Author:    Jochen Wiedmann
  27. ***             Am Eisteich 9
  28. ***             72555 Metzingen
  29. ***             Germany
  30. ***
  31. ***             Phone: (+0049) 7123 / 14881
  32. ***             Internet: wiedmann@neckar-alb.de
  33. **/
  34.  
  35.  
  36.  
  37.  
  38.  
  39. /**
  40. ***  Include files
  41. **/
  42. #define __USE_SYSBASE
  43. #ifndef IPDIAL_H
  44. #include "IPDial.h"
  45. #endif
  46. #include <exec/execbase.h>
  47.  
  48.  
  49.  
  50. ULONG setvar(STRPTR var, STRPTR val, ULONG flags)
  51.  
  52. { LONG save = FALSE;
  53.   ULONG success = TRUE;
  54.  
  55.   if (flags & GVF_SAVE_VAR) {
  56.       flags |= GVF_GLOBAL_ONLY;
  57.   }
  58.   if ((flags & GVF_SAVE_VAR)  &&  SysBase->LibNode.lib_Version < 39)
  59.   { flags &= ~GVF_SAVE_VAR;
  60.     save = TRUE;
  61.   }
  62.  
  63.   if (!SetVar(var, val, -1, LV_VAR | flags))
  64.   { return(FALSE);
  65.   }
  66.  
  67.   if (save)
  68.   { BPTR dir, oldDir;
  69.     BPTR file;
  70.  
  71.     success = FALSE;
  72.  
  73.     if ((dir = Lock((STRPTR) "ENVARC:", SHARED_LOCK)))
  74.     { oldDir = CurrentDir(dir);
  75.  
  76.       if ((file = Open(var, MODE_NEWFILE)))
  77.       { LONG len = strlen((char*) val);
  78.  
  79.     if (Write(file, val, len) == len)
  80.     { success = TRUE;
  81.     }
  82.  
  83.     Close(file);
  84.       }
  85.  
  86.       CurrentDir(oldDir);
  87.     }
  88.   }
  89.  
  90.   return(success);
  91. }
  92.